﻿using Prism.Commands;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfApp_PrismDialog.ViewModels;

public class UCDetailViewModel : IDialogAware
{
    
    public DelegateCommand? CloseWindow { get; set; }

    public string Title => "Hello Dialog";

    public UCDetailViewModel()
    {
        CloseWindow = new DelegateCommand(() => 
        {
            //回复参数
            IDialogResult dialogResult = new DialogResult();
            dialogResult.Parameters.Add("AAA",true);
            RequestClose?.Invoke(dialogResult);
        });
    }

    public event Action<IDialogResult> RequestClose;

    //当前打开的窗口是否允许关闭
    public bool CanCloseDialog()
    {
        return true;
    }

    //当前打开窗口关闭时候的执行逻辑
    public void OnDialogClosed()
    {
        
    }

    //当前打开窗口打开时候的执行逻辑
    public void OnDialogOpened(IDialogParameters parameters)
    {
        string _username = string.Empty;
        parameters.TryGetValue("username", out _username);
    }
}
